//
//  AppDelegate.swift
//  新浪微博
//
//  Created by liuyanchi on 16/7/28.
//  Copyright © 2016年 liuyanchi. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
       print(NSHomeDirectory())
        
        
        // window的设置
        window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
        
        // MARK:-- 根据token进行判断跳转到那个界面
        // model?.access_token == nil ? false : true
        if LYCLoginViewModel.shareInstance.isLogin {
        
            // 登陆成功过
        window?.rootViewController =
            
            LYCWelcomeViewController()
        
        }else{
        
            // 未登录
        window?.rootViewController =
            
            LYCTabBarViewController()
        
        }
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeVC:", name: kNotificationChangeViewController, object: nil)
        
        
        
        window?.makeKeyAndVisible()
        
        setupNavColor()
        
        return true
    }


    // 通知的监听事件的实现方法
    @objc private func changeVC(noti:NSNotification){
    
    
        if noti.object is LYCLoginViewController {
            
            window?.rootViewController = LYCWelcomeViewController()
            
            
        }else{
            
            window?.rootViewController = LYCTabBarViewController()
            
        }
    }
    
    
    
    
    
        // MARK:-- 设置导航栏的item颜色
    private func setupNavColor(){
    
    UINavigationBar.appearance().tintColor = UIColor.orangeColor()
    
    }
    
// MARK:--移除通知
    deinit{
    
    NSNotificationCenter.defaultCenter().removeObserver(self)
    
    
    }
   

}

